<?php
class fcp_utils
{
	function GetCommentDatetime($commentDate)
	{
		$strTime = strtotime($commentDate);			
		$time = time() - $strTime; // to get the time since that moment

		$tokens = array (
			31536000 => 'year',
			2592000 => 'month',
			604800 => 'week',
			86400 => 'day',
			3600 => 'hour',
			60 => 'minute',
			1 => 'second'
		);

		foreach ($tokens as $unit => $text) {
			if ($time == 0)
				return 'few seconds ago';		
			if ($time < $unit) continue;
			
			$numberOfUnits = floor($time / $unit);
			
			if($text == 'second' && $numberOfUnits < 5)
				return 'few seconds ago';
			elseif($text == 'second' || $text == 'minute' || $text == 'hour')
				return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'').' ago';
			else
				return date('d F Y', $strTime);
		}
	}
}
?>